Skip to content

Instantly share code, notes, and snippets.

@queeup
Last active April 25, 2025 13:06
Show Gist options
  • Save queeup/1666bc0a5558464817494037d612f094 to your computer and use it in GitHub Desktop.
Save queeup/1666bc0a5558464817494037d612f094 to your computer and use it in GitHub Desktop.
Nix package manager install (single user) on Fedora Silverblue

Nix package manager on Fedora Silverblue

Warning

Disable composefs or enable root.transient before install and use nix on Fedora Silverblue 42.

Disable composefs

sudo rpm-ostree kargs --append='ostree.prepare-root.composefs=0' --reboot

Install nix

curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | \
    sh -s -- install ostree --no-confirm --persistence=/var/lib/nix

Fix sudo

echo "Defaults  secure_path = /nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:$(sudo printenv PATH)" | sudo tee /etc/sudoers.d/nix-sudo-env

Old way

  • This is a single user install.

  • For multi user install and without changing selinux mode: https://gist.github.com/matthewpi/08c3d652e7879e4c4c30bead7021ff73

  • Please note that these instructions are not offically supported or condoned by Nix and are not guaranteed to always work, but from my testing everything seems to work perfectly fine.

  • Change SELinux mode to permissive

    sudo setenforce Permissive
    sudo sed -i 's/SELINUX=enforcing/SELINUX=permissive/' /etc/selinux/config
  • Create the nix directory in a persistent location

    sudo mkdir /var/lib/nix
    sudo chown $USER:$USER /var/lib/nix
  • /etc/systemd/system/[email protected]

    [Unit]
    Description=Enable mount points in / for ostree
    ConditionPathExists=!%f
    DefaultDependencies=no
    Requires=local-fs-pre.target
    After=local-fs-pre.target
    
    [Service]
    Type=oneshot
    ExecStartPre=chattr -i /
    ExecStart=mkdir -p '%f'
    ExecStopPost=chattr +i /
  • /etc/systemd/system/nix.mount

    [Unit]
    Description=Nix Package Manager
    DefaultDependencies=no
    After[email protected]
    Wants[email protected]
    Before=sockets.target
    After=ostree-remount.service
    BindsTo=var.mount
    
    [Mount]
    What=/var/lib/nix
    Where=/nix
    Options=bind
    Type=none
    
    [Install]
    WantedBy=local-fs.target
  • Enable and mount the nix mount.

    # Ensure systemd picks up the newly created units
    sudo systemctl daemon-reload
    # Enable the nix mount on boot.
    sudo systemctl enable nix.mount
    # Mount the nix mount now.
    sudo systemctl start nix.mount
  • Install Nix

    sh <(curl -L https://nixos.org/nix/install) --no-daemon
  • Load Nix into your environment. Enable bash/fish/zhs completion for nix installed commands

    Load Nix into your environment. The installer modified ~/.bash_profile, but it isn't used when you start a terminal from desktop, it's only used when using a full shell login with bash -l, which doesn't happen on silverblue.

    tee --append $HOME/.bashrc <<EOF
    # Nix Package Manager
    if [ -e $HOME/.nix-profile/etc/profile.d/nix.sh ]; then
        source $HOME/.nix-profile/etc/profile.d/nix.sh;
    fi
    EOF
  • Links:

@bubuntux
Copy link

bubuntux commented Apr 21, 2025

currently getting errors when trying to install

 INFO Step: Enable (and start) the systemd unit `nix.mount`
ERROR Error saving receipt: RecordingReceipt("/nix", Os { code: 30, kind: ReadOnlyFilesystem, message: "Read-only file system" })
Error: 
   0: Install failure
   1: Error executing action
   2: Action `start_systemd_unit` errored
   3: Failed to execute command `"systemctl" "start" "nix.mount"`
      stdout: 
      stderr: A dependency job for nix.mount failed. See 'journalctl -xe' for details.

   3: exited with status code: 1
   3: 

and i see

nix-directory.service - Enable mount points in / for ostree
     Loaded: loaded (/etc/systemd/system/nix-directory.service; static)
    Drop-In: /usr/lib/systemd/system/service.d
             └─10-timeout-abort.conf, 50-keep-warm.conf
     Active: failed (Result: exit-code) since Mon 2025-04-21 18:24:43 CDT; 2min 45s ago
 Invocation: de9c4fc3f7a04a6bb48b69570af4797f
    Process: 8199 ExecStartPre=chattr -i / (code=exited, status=1/FAILURE)
    Process: 8200 ExecStopPost=chattr +i / (code=exited, status=1/FAILURE)
   Mem peak: 1.4M
        CPU: 6ms

any ideas?
composefs is disabled

i was able to fix it enabling composefs and doing this

@queeup
Copy link
Author

queeup commented Apr 24, 2025

I have no idea. Did you reboot after disabling composefs and before installing nix?

@bubuntux
Copy link

I have no idea. Did you reboot after disabling composefs and before installing nix?

Yes, on the other thread they report that in some instances disabling composefs is not enought, doing the other suggestion work tho

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment